<?php
class CompaniesFForm extends BaseFormAdmin{
	public function configure(){
		$inLD = AdminArrayData::getInLongduc();
		$this->setWidgets(array(
				'staff_number_id'		=> new sfWidgetFormDoctrineChoice(array(
						'model' 		=> 'MasterCompanyStaffNumbers',
						'query'			=> Doctrine_Query::create()
											->select('c.id, c.number_name as name')
											->from('MasterCompanyStaffNumbers c')
											->where('c.is_enabled = 1 AND c.is_deleted = 0 AND (c.updated_at IS NULL OR c.updated_at >= c.created_at)'),
						'multiple' 		=> false,
						'add_empty' 	=> __('option_select', null, 'table_list'))),
				'company_name'			=> new sfWidgetFormInputText(),
				'company_description' 	=> new sfWidgetFormTextarea(),
				'location_city_id'        	=> new sfWidgetFormDoctrineChoice(array('model' => 'LocationCities', 'query' => Doctrine_Query::create()->select('b.id, b.name')->from('LocationCities b')->orderBy('b.name'),'multiple' => false, 'add_empty' => __('option_select', null, 'table_list'))),
				'location_district_id' 		=> new sfWidgetFormInputText(),
				'address'					=> new sfWidgetFormInputText(),
				'website'					=> new sfWidgetFormInputText(),
				'phone_number'			=> new sfWidgetFormInputText(),
				'fax_number'			=> new sfWidgetFormInputText(),
				'is_in_longduc' 		=> new sfWidgetFormChoice(array('choices'=>$inLD,'expanded'=>true)),
				'email'					=> new sfWidgetFormInputText(),
				
		));

		$this->setValidators(array(
				'staff_number_id'       	=> new sfValidatorDoctrineChoice(array(
						'model' => 'MasterCompanyStaffNumbers',
						'query' => Doctrine_Query::create()
									->select('c.id, c.number_name as name')
									->from('MasterCompanyStaffNumbers c')
									->where('c.is_enabled = 1 AND c.is_deleted = 0 AND (c.updated_at IS NULL OR c.updated_at >= c.created_at)'),
						'required' => true),
						array('required'=> 'input staff_number_id')),
				'company_name'        => new sfValidatorString(array('max_length' => 255, 'required' => true)),
				'company_description' => new sfValidatorString(array('required' => false)),
				'location_city_id'		=> new sfValidatorString(array('required' => false)),
				'location_district_id'	=> new sfValidatorString(array('required' => false)),
				'is_in_longduc'			=> new sfValidatorChoice(array('choices'=>array_keys($inLD))),
				'website' 			=> new sfValidatorString(array('required' => false)),
				'address' 			=> new sfValidatorString(array('required' => false)),
				'phone_number' 		=> new sfValidatorString(array('required' => false)),
				'fax_number' 		=> new sfValidatorString(array('required' => false)),
				'email' 			=> new sfValidatorString(array('required' => false)),
				
				
		));
		
		parent::configure();
		$this->setDefault('is_in_longduc', '1');
		/*
		 * Setting name of form
		*/
		$this->widgetSchema->setNameFormat('Companies[%s]');
		$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
	}
	
}
